package com.yu.java.se;

import com.google.common.collect.Lists;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ForkJoinPool;

/**
 * @author wu
 * @create 2022-11-15-16:12
 */
public class CompletableFutureDemo {
    public static void main(String[] args) {
        List<Long> ids = new ArrayList<>();
        List<List<Long>> partitionLists = Lists.partition(ids, 8);
        ForkJoinPool pool = new ForkJoinPool();
        List<CompletableFuture<?>> futures = new ArrayList<>();
        partitionLists.forEach(partitionids -> {
            List<String> strings = new ArrayList<>();
            CompletableFuture<List<String>> completableFuture = CompletableFuture.supplyAsync(() -> {

                partitionids.forEach(id -> {
                    strings.add(id.toString());

                });
                return strings;
            },pool);
            futures.add(completableFuture);
        });
        List<String> stringsAlList = new ArrayList<>();
        futures.forEach(future -> {
            try {
                stringsAlList.addAll((List<String>) future.get());
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
    }
}
